package com.example.zookeeperlock.testcase;

import com.example.zookeeperlock.highlock.impl.SimpleZkLock;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: zhangrongqing
 * @Date: 2020/9/1 14:21
 */
public class SimpleLockCase {

    ExecutorService executorService = Executors.newFixedThreadPool(10);

    public void testSimpleLock() {

        for (int i = 0; i < 10; i++) {
            executorService.submit(() -> {
                SimpleZkLock simpleZkLock = new SimpleZkLock();

                simpleZkLock.getLock();

                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                simpleZkLock.releaseLock();
            });
        }

        executorService.shutdown();
    }


    public static void main(String[] args) {
        new SimpleLockCase().testSimpleLock();
    }
}
